<template>
  <a-modal
      :title="title"
      :width="800"
      :visible="visible"
      :confirmLoading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
      :footer="null"
      cancelText="关闭">

    <table id="table_report" class="table table-striped table-bordered table-hover">

      <tr>
        <td style="width:90px;text-align: right;padding-top: 125px;">基本信息:</td>
        <td>
          <p style="float: left;">


            车牌号：<span id="plateNo">
           {{ result.plateNo }}
                    </span><br>


            停车场名称：<span id="parkName">
           {{ result.parkName }}
                    </span><br>


            停车场编号：<span id="parkCode">
           {{ result.parkCode }}
                    </span><br>
            当前的停车费用(元)：<span id="chargeUnpaid" v-text="chargeUnpaid(result.chargeUnpaid)">
<!--           {{result.chargeUnpaid }}-->
                    </span><br>

            已支付费用(元)：<span id="chargePaid" v-text="chargePaid(result.chargePaid)">
                    </span><br>
            入场时间：<span id="enterTime">
           {{ result.enterTime }}
                    </span><br>
            出场时间：<span id="outTime">
           {{ result.outTime }}
                    </span><br>
            停车时长：<span id="chargeDuration" v-text="chargeDuration(result.chargeDuration)">
                    </span><br>
            预付费用：<span id="chargePrepaid">
           {{ result.chargePrepaid }}
                    </span><br>
            订单状态：<span id="orderStatus" v-text="orderStatus(result.orderStatus)">
                    </span><br>
            总费用(元)：<span id="chargeTotalFee" v-text="chargeTotalFee(result.chargeTotalFee)">
                    </span><br>
            支付类型：<span id="payType" v-text="payType(result.payType)">
                    </span><br>
            创建时间：<span id="createTime">
           {{ result.createTime }}
                    </span><br>
          </p>
        </td>
      </tr>
      <tr>
        <td style="width:90px;text-align: right;padding-top: 270px;">详情:</td>
        <td>
          <p style="float: left;">

            <span id="openId" v-show="result.openId">微信停车公众号openid：{{ result.openId }}</span><br v-show="result.openId">

            <span id="nickName" v-show="result.nickName">昵称：{{ result.nickName }}</span><br v-show="result.nickName">

            <span id="serialNo" v-show="result.serialNo">设备序列号：{{ result.serialNo }}</span><br v-show="result.serialNo">

            <span id="armCode" v-show="result.armCode">停车场出口id：{{ result.armCode }}</span><br v-show="result.armCode">

            <span id="armName" v-show="result.armName">停车场出口名称：{{ result.armName }}</span><br v-show="result.armName">


            <span id="ipAddr" v-show="result.ipAddr">设备ip地址：{{ result.ipAddr }}</span><br v-show="result.ipAddr">


            <span id="parkLogId" v-show="result.parkLogId">停车记录id：{{ result.parkLogId }}</span><br v-show="result.parkLogId">

            <span id="carEnterId" v-show="result.carEnterId">车辆入场ID：{{ result.carEnterId }}</span><br v-show="result.carEnterId">

            <span id="chargeDue" v-show="result.chargeDue">原停车费用(元)：{{ result.chargeDue/100 }}</span><br v-show="result.chargeDue">

            <span id="orderStatusDesc" v-show="result.orderStatusDesc">订单状态描述：{{ result.orderStatusDesc }}</span><br v-show="result.orderStatusDesc">

            <span id="version" v-show="result.version">版本号：{{ result.version }}</span><br v-show="result.version">

            <span id="totalAmt">订单总金额(元)：{{ result.totalAmt /100 }}</span><br>


            <span id="pointAmt">积分抵扣金额(元)：{{ result.pointAmt /100 }}</span><br>


            <span id="ecouponAmt">电子券抵扣金额(元)：{{ result.ecouponAmt /100 }}</span><br>


            <span id="merDiscAmt">优惠立减金额(元)：{{ result.merDiscAmt /100 }}</span><br>

            <span id="couponAmt">优惠券金额(元)：{{ result.couponAmt /100 }}</span><br>

            <span id="outTradeNo">商户系统订单号：{{ result.outTradeNo }}</span><br>

            <span id="orderId">行内系统订单号：{{ result.orderId }}</span><br>


            <span id="payTime" v-text="translatePayTime(result.payTime)"></span><br>


            <span id="totalDiscAmt">总优惠金额(商户优惠立减金额+银行补贴金额，单位元)：{{ result.totalDiscAmt }}</span><br>


            <span id="merId">商户线下档案编号：{{ result.merId }}</span><br>


            <span id="attach" v-show="result.attach">商户上送的附加数据：{{ result.attach }}</span><br v-show="result.attach">


            <span id="custId">用户唯一标识：{{ result.custId }}</span><br>

            <span id="bankDiscAmt">银行补贴金额(元)：{{ result.bankDiscAmt /100 }}</span><br>


            <span id="paymentAmt">用户实际扣减金额(元)：{{ result.paymentAmt /100 }}</span><br>

            <!--支付类型-->
            <span id="sourceType" v-text="sourceType(result.sourceType)"></span><br>

            <!--发票状态-->
            <span id="billStatus" v-show="result.billStatus" v-text="billStatus(result.billStatus)"></span><br v-show="result.billStatus">

            <!--是否有牌车-->
            <span id="carType" v-show="result.carType" v-text="carType(result.carType)"></span><br v-show="result.carType">


            <span id="invoiceBill" v-show="result.invoiceBill">发票请求流水号：{{ result.invoiceBill }}</span><br v-show="result.invoiceBill">

            <!--发票红冲类别-->
            <span id="redType" v-show="result.redType" v-text="redType(result.redType)"></span><br v-show="result.redType">

            <span id="redInvoiceBill" v-show="result.redInvoiceBill">红冲发票请求流水号：{{ result.redInvoiceBill }}</span><br v-show="result.redInvoiceBill">

            <span id="updateTime">修改时间：{{ result.updateTime }}</span><br>
          </p>
        </td>
      </tr>

      <tr>
        <td style="text-align: center;" colspan="10">
          <a-button type="primary" @click="close">关闭</a-button>
        </td>
      </tr>
    </table>

  </a-modal>
</template>

<script>
import {httpAction} from '@/api/manage'
import pick from 'lodash.pick'
import moment from "moment"

export default {
  name: "ParkOrderInfoModal",
  data() {
    return {
      title: "操作",
      visible: false,
      model: {},
      labelCol: {
        xs: {span: 24},
        sm: {span: 5},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16},
      },
      result: {},
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {},
      url: {
        add: "/order/parkOrderInfo/add",
        edit: "/order/parkOrderInfo/edit",
      },
    }
  },
  created() {
  },
  methods: {
    carType(t) {
      let text = '是否有牌车：'
      if (t === '1' || t===1) {
        return text+"有牌车"
      } else if (t === '2' || t===2) {
        return text+"无牌车"
      }
      return text + '未知'
    },
    redType(t) {
      let text='发票红冲类别：'
      if (t === 0 || t==='0') {
        return text+"正常"
      } else if (t === 1 || t==='1') {
        return text+"红冲"
      }
      return text + '未知'
    },
    chargeTotalFee(t) {
      return (t / 100).toFixed(2);
    },
    chargeDuration(t) {
      var day = parseInt(t / 60 / 24);
      var hour = parseInt(t / 60 % 24);
      var min = parseInt(t % 60);
      t = "";
      if (day > 0) {
        t = day + "天";
      }
      if (hour > 0) {
        t += hour + "小时";
      }
      if (min > 0) {
        t += parseFloat(min) + "分钟";
      }

      return t == "" ? "0分钟" : t;
    },
    chargePaid(t) {
      return (t / 100).toFixed(2);
    },
    chargeUnpaid(t) {
      return (t / 100).toFixed(2);
    },
    orderStatus(t) {
      if (t === 1 || t === '1') {
        return "未支付"
      } else if (t === 2 || t === '2') {
        return "支付成功"
      } else if (t === 3 || t === '3') {
        return "支付失败"
      }
    },
    translatePayTime(t){
      let text = '支付完成时间：'
      if(t!==undefined&&t!==null)
      {
        if(t.length===14)
        {
          return text+t.slice(0,4)+'-'+t.slice(4,6)+'-'+t.slice(6,8)+' '+t.slice(8,10)+':'+t.slice(10,12)+':'+t.slice(12,14)
        }
        else {
          return text+t
        }
      }
      return text
    },
    billStatus(t) {
      let text = '发票状态：'
      if (t === 1 || t === '1') {
        return text+"已开票"
      } else if (t === 2 || t === '2') {
        return text+"未申请"
      } else if (t === 3 || t === '3') {
        return text+"开票失败"
      } else if (t === 4 || t === '4') {
        return text+"红冲"
      } else if (t === 5 || t === '5') {
        return text+"开票申请中"
      } else if (t === 6 || t === '6') {
        return text+"红冲开票申请中"
      }
      return text + '未知'
    },
    sourceType(t) {
      let text = '支付类型：'
      if (t === 1  || t === '1') {
        return text+"聚合支付"
      } else if (t === 2  || t === '2') {
        return text+"无感支付"
      }
      return text+ '未知'
    },
    payType(t) {
      if (t === 1  || t === '1') {
        return "微信";
      } else if (t === 2  || t === '2') {
        return "支付宝";
      } else if (t === 3  || t === '3') {
        return "无感支付";
      } else if (t === 4  || t === '4') {
        return "全免劵";
      } else if (t === 5  || t === '5') {
        return "储值卡";
      } else if (t === 6  || t === '6') {
        return "线下收费";
      }
    },
    add() {
      this.edit({});
    },
    edit(record) {
      Object.assign(this.result, record);
      this.visible = true;
    },
    close() {
      this.$emit('close');
      this.visible = false;
    },
    handleOk() {
      const that = this;
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          let formData = Object.assign(this.model, values);
          //时间格式化
          formData.updateTime = formData.updateTime ? formData.updateTime.format('YYYY-MM-DD HH:mm:ss') : null;

          httpAction(httpurl, formData, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            that.close();
          })


        }
      })
    },
    handleCancel() {
      this.close()
    },


  }
}
</script>

<style lang="less" scoped>

</style>
